<? 
	include('base.php');
	User::protect();
	include_class('general_media');
	include_class('m2');
	$id = ($_GET['id'] > 0 && is_numeric($_GET['id'])) ? $_GET['id'] : 0;
	$gm = new GeneralMedia();
	if ($id != 0) {
		$ma = MediaArea::get($id);
		if (!db::isError($ma)) {
			$gm->setAreaObject($ma);
			$isNotGeneralMedia = !$ma->isGeneralMedia();
		}
	}

	if ($_POST['submit'] && !db::isError($ma)) {
		$res = $ma->updateInformation($_POST, $gm);
		if (!db::isError($res)) {
			header('Location: media.php?id=' . $ma->getID());
			exit;
		}
	}
	$editors = array('description');
	$section = 'media';
	$page_title = 'Edit Media Area';
	include('layout/header.php');


if ($isNotGeneralMedia) { 

	Error::outputDialog('Return to Media','media.php', 'You may only edit general media here. Any media that has been added to a specific band member, show or release must be edited in its appropriate section.');
	

 } else if (!db::isError($ma)) { ?>
 
 	<div id="breadcrumb">
		<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="media.php">Media&nbsp;&#62;</a>
	<? 
		if (!db::isError($ma)) {
			$breadcrumb = $ma->getAreaTrail();
			if ($breadcrumb) { 
				foreach($breadcrumb as $maBC) {
					echo('<a href="media.php?id=' . $maBC->getID() . '">' . $maBC->getTitle() . '&nbsp;&#62;&nbsp;</a>');
				}
			}
		}	
		echo("Edit Media Area");
	?>
	</div>
	<?

	if (db::isError($res)) { 
		$res->outputList();
	}
	?>

	<h1>edit entry:</h1>
	<div class="inset">
	<form id="" action="<?=$_GLOBALS['PHP_SELF']?>" method="post">
	<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
	<tr>
		<td width="50%"><strong>Name:</strong><br/>
		<input type="text" class="text" name="title" id="title" value="<?=$ma->getTitle()?>"></td>
		<td width="50%"><strong>Type of Area:</strong><br/>
		<? if ($ma->getDisplay() == 'grid') { ?>Photo Gallery<? } else { ?>Audio/Video List<? } ?>

		</td>
	</tr>
	<tr>
		<td colspan="2">
			<strong>Located In</strong><br/>
			<? $malist = $ma->getAllGeneralAreas(); ?>
			<select name="parent_id">
			<?
			if ($ma->getParentID() == 0) {
				echo('<option value="0" selected>[CURRENT] * Top Level</option>');
			} else {
				echo('<option value="0">* Top Level</option>');
			} 	
			foreach($malist as $_ma) {	
				if ($_ma->getID() != $ma->getID()) { 
					echo('<option value="' . $_ma->getID() . '"');
					if ($_ma->getID() == $ma->getParentID()) {
						echo(' selected>[CURRENT] ' . $_ma->getTitle() . '</option>');
					} else {
						echo('>' . $_ma->getTitle() . '</option>');
					}
				}
			} ?>		
			</select>
		</td>
	</tr>
	</table>
	<div class="edit-form">
		<strong>Description</strong><br/><textarea id="description" name="description" value="" class="full"><?=$ma->getDescription()?></textarea></td>
	</div>
	<div class="edit-form">
		<input type="submit" value="Update Area" name="submit" class="button">
		<input type="submit" value="Exit Without Editing" name="preview" onclick="location.href='media.php?id=<?=$id?>'; return false" class="button"></td>
	</div>
	
	
	</div>

<? } else { ?>

	<div id="breadcrumb">
		<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="media.php">Media&nbsp;&#62;</a>&nbsp;&nbsp;Invalid Entry
	</div>
	<?
	
	$ma->outputDialog('Return to Media','media.php');
		
} ?>

<? include('layout/footer.php'); ?>
